﻿<?php

loginYangZheng($_POST['username'],$_POST['pass']);

function loginYangZheng($username,$pass){


	 session_start();

	if(!empty($_POST)){


		$link=mysqli_connect('localhost', 'root', 'root', 'weizandata');

		$link->query("set names utf8");

		$mq=mysqli_query($link,"SELECT username,pass,name_a,city FROM userInfo");

		$rows= mysqli_affected_rows($link);

		$i1=0;

		$loginBool=false;
		
		foreach (mysqli_fetch_all($mq, 1) as $qii){

			if($username==$qii['username'] and $pass==$qii['pass'])

			{		
					$loginBool=true;
					$_SESSION['username']=$qii['username'];
					$_SESSION['name_a']=$qii['name_a'];
					$_SESSION['city']=$qii['city'];
					header("Location:jiemian.php");
			}else{

				$i1++;	

			}
		}


		if(!$loginBool){

			
			header('Location:dingxiang.php?url=index.php&info=您输入的密码错误3秒后跳转到登录页面');
		}




	}

}

function yanzheng(){


	session_start();

	if(isset($_SESSION['username'])){

		header('Location:dingxiang.php?url=jiemian.php&info=您已经已登录3秒后自动跳转到页面');

	}

}

function weiDengLu(){


	session_start();

	if(!isset($_SESSION['username'])){

		header('Location:dingxiang.php?url=index.php&info=您未登录3秒后自动跳转到登录页面');

	}

}



?>